import { Module, Global } from '@nestjs/common';
import { DatabaseModule } from '../db/database.module';
import { MongoProviders } from '../db/database.models';
import { RedisModule } from '@liaoliaots/nestjs-redis';
import config from 'src/config';
import { LoggerModule } from 'src/common/modules/logger/logger.module';
import { QueuesModule } from 'src/common/modules/queues/queues.module';
import { HttpCacheModule } from './modules/cache/http.cache.module';
import { MongooseModule } from '@nestjs/mongoose';
import { createConnectUrl } from 'src/db/database.providers';
import { CommonScheduleModule } from './modules/schedule/schedule.module';
import { EventEmitterModule } from '@nestjs/event-emitter';

/**全局公共模块 */
@Global()
@Module({
	imports: [
		/**数据库模块 */
		DatabaseModule,
		MongooseModule.forRoot(createConnectUrl()),
		/**日志模块 */
		LoggerModule,
		/**事件模块 */
		EventEmitterModule.forRoot(),
		/**队列 */
		QueuesModule,
		/**定时任务 */
		CommonScheduleModule,
		/**http缓存模块 */
		HttpCacheModule,
		/**redis模块 */
		RedisModule.forRoot({
			config:{
				url:`redis://:${config.redis.password}@${config.redis.host}:${config.redis.port}/${config.redis.db}`,
				namespace:"default"
			}
		}),
	],
	controllers: [],
	providers: [
		...MongoProviders,
	],
	exports: [
		...MongoProviders,
	],
})
export class CommonModule { }
